home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / bin / make_link < prev    next >
Encoding:
Text File  |  1997-07-08  |  2.1 KB  |  84 lines

  1. #!/bin/sh
  2. #
  3. #       $Id: make_link,v 1.11 1996/11/23 05:30:21 ali Exp $
  4. #
  5. # make_link
  6. #
  7. # This script places a symbolic link named $2 to existing file $1.
  8. #       $1 - The target file or directory.
  9. #       $2 - The link name
  10. #
  11. # Note: Some versions of Unix test use -h for symlinks, others use -L, and
  12. #       some lack the ability altogether. This means that we have to limit
  13. #       ourselves to the basic codes (r, w, d) which don't go far enough.
  14. #    However, all systems have /bin/ls...
  15. #
  16.  
  17.  
  18. if [ \(  -f /bin/dirname \) -o \(  -f /usr/5bin/dirname \) ]; then
  19.    UDIR=`dirname $0`
  20. else
  21.    UDIR=`echo $0 | awk -F\/ '{if(NF==1)
  22.    printf(".\n");else{for(i=1;i<NF;i++){if(i>1)printf("%s","/"); printf("%s",$i);}printf("\n")}}'`
  23. fi
  24. echo " "
  25.  
  26. #### LINKDIR=`dirname $2`
  27. LINKDIR=`echo $2 | sed 's?/[^/]*$??'`
  28. LINK_DONE=0
  29. if [ "`/bin/ls -1 $1 2> /dev/null`" = "" ]; then
  30.     echo "    Warning: Target file does not exist:
  31.         $1
  32. "
  33. fi
  34.  
  35. if [ ! -d $LINKDIR ]; then
  36.     echo "    Unable to create symbolic link:
  37.         $LINKDIR does not exist."
  38.     exit 1
  39. fi
  40. if [ ! -w $LINKDIR ]; then
  41.     echo "    Unable to create symbolic link:
  42.         $LINKDIR is not writable."
  43.     exit 1
  44. fi
  45.  
  46. # If its already there, and is a directory, assume all is OK:
  47. if [ -d $2 ]; then 
  48.         echo "    Directory " $2 " already exists --- No link is needed."
  49.         exit 0
  50. fi
  51.  
  52. if [ "`/bin/ls -1 $2 2> /dev/null`" != "" ]; then
  53.   cmp $1 $2 > /dev/null 2>&1
  54.   if [ "$?" = "0" ]; then               # Already there and the same? OK...
  55.       LINK_DONE="1"
  56.   else
  57.     echo "    Link Name: $2
  58.     Points at: $1
  59.     A file with the same name as the desired symbolic link
  60.       already exists and is different from the pointed at file."
  61.     if [ `sh $UDIR/yesno "Remove link file to make new link possible"` = 0 ]
  62.     then
  63.       echo "    Link aborted."
  64.       exit 1;
  65.     fi
  66.     echo " "
  67.     rm -f $2;
  68.   fi
  69. fi
  70.  
  71. if [ "$LINK_DONE" = 0 ]; then
  72.   ln -s $1 $2 > /dev/null 2>&1
  73.   if [ "`/bin/ls -1 $2 2> /dev/null`" = "" ]; then
  74.     echo "    Unable to create symbolic link:
  75.         $2"
  76.     exit 1
  77.   fi
  78. fi
  79.  
  80. echo "    Link Name: $2
  81.     Points at: $1"
  82.  
  83. exit 0
  84.